package com.test.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.test.entity.UserBorrowDetail;
import com.test.service.BorrowServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;

@RestController
@RequestMapping("/borrow")
public class BorrowController {

    @Autowired
    private BorrowServiceImpl borrowService;

    @GetMapping("/{uid}")
    //@HystrixCommand(fallbackMethod = "onError")
    //使用@HystrixCommand来指定备选方案
    public UserBorrowDetail findUserBorrows(@PathVariable("uid") int uid){
        System.out.println("开始向其他服务获取信息");
        return borrowService.getUserBorrowDetailByUid(uid);
    }

    //备选方案，这里直接返回空列表了
    //注意参数和返回值要和上面的一致
    //UserBorrowDetail onError(int uid){
    //    System.out.println("服务错误，进入备选方法！");
    //    return new UserBorrowDetail(null, Collections.emptyList());
    //}


}
